﻿@inherits BaseChartComponent

<CascadingValue Value="this" IsFixed="true">
    @ChildContent
</CascadingValue>

@code {
    private IDictionary<string, object> feature = new Dictionary<string, object>();
    private IDictionary<string, object> iconStyle = new Dictionary<string, object>();
    private IDictionary<string, object> emphasis = new Dictionary<string, object>();
    private IDictionary<string, object> tooltip = new Dictionary<string, object>();

    protected override string ComponentName => "toolbox";

    #region 参数

    /// <summary>
    /// 组件 ID
    /// </summary>
    [Parameter]
    public string? id { get; set; }

    /// <summary>
    /// 是否显示工具栏组件
    /// </summary>
    [Parameter]
    public bool? show { get; set; }

    /// <summary>
    /// 工具栏 icon 的布局朝向。可选：'horizontal' 'vertical'
    /// </summary>
    [Parameter]
    public string? orient { get; set; }

    /// <summary>
    /// 工具栏 icon 的大小
    /// </summary>
    [Parameter]
    public int? itemSize { get; set; }

    /// <summary>
    /// 工具栏 icon 每项之间的间隔
    /// </summary>
    [Parameter]
    public int? itemGap { get; set; }

    /// <summary>
    /// 是否在鼠标 hover 的时候显示每个工具 icon 的标题
    /// </summary>
    [Parameter]
    public bool? showTitle { get; set; }

    /// <summary>
    /// 所有图形的 zlevel 值
    /// </summary>
    [Parameter]
    public int? zlevel { get; set; }

    /// <summary>
    /// 组件的所有图形的z值
    /// </summary>
    [Parameter]
    public int? z { get; set; }

    /// <summary>
    /// 工具栏组件离容器左侧的距离
    /// </summary>
    [Parameter]
    public string? left { get; set; }

    /// <summary>
    /// 工具栏组件离容器上侧的距离
    /// </summary>
    [Parameter]
    public string? top { get; set; }

    /// <summary>
    /// 工具栏组件离容器右侧的距离
    /// </summary>
    [Parameter]
    public string? right { get; set; }

    /// <summary>
    /// 工具栏组件离容器下侧的距离
    /// </summary>
    [Parameter]
    public string? bottom { get; set; }

    /// <summary>
    /// 工具栏组件的宽度
    /// </summary>
    [Parameter]
    public string? width { get; set; }

    /// <summary>
    /// 工具栏组件的高度
    /// </summary>
    [Parameter]
    public string? height { get; set; }

    #endregion

    protected override Task SetParametersAsync()
    {
        if (!string.IsNullOrEmpty(id))
            FillSetting("id", id);

        if (show.HasValue)
            FillSetting("show", show.Value);

        if (!string.IsNullOrEmpty(orient))
            FillSetting("orient", orient);

        if (itemSize.HasValue)
            FillSetting("itemSize", itemSize.Value);

        if (itemGap.HasValue)
            FillSetting("itemGap", itemGap.Value);

        if (showTitle.HasValue)
            FillSetting("showTitle", showTitle.Value);

        if (zlevel.HasValue)
            FillSetting("zlevel", zlevel.Value);

        if (z.HasValue)
            FillSetting("z", z.Value);

        if (!string.IsNullOrEmpty(left))
            FillSetting("left", left);

        if (!string.IsNullOrEmpty(top))
            FillSetting("top", top);

        if (!string.IsNullOrEmpty(right))
            FillSetting("right", right);

        if (!string.IsNullOrEmpty(bottom))
            FillSetting("bottom", bottom);

        if (!string.IsNullOrEmpty(width))
            FillSetting("width", width);

        if (!string.IsNullOrEmpty(height))
            FillSetting("height", height);

        return Task.CompletedTask;
    }

    public void SetFeature(Action<IDictionary<string, object>> action)
    {
        FillSetting("feature", feature);
        action?.Invoke(feature);
    }

    public void SetIconStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("iconStyle", iconStyle);
        action?.Invoke(iconStyle);
    }

    public void SetEmphasis(Action<IDictionary<string, object>> action)
    {
        FillSetting("emphasis", emphasis);
        action?.Invoke(emphasis);
    }

    public void SetTooltip(Action<IDictionary<string, object>> action)
    {
        FillSetting("tooltip", tooltip);
        action?.Invoke(tooltip);
    }
}
